package com.dfqy.service;

import com.dfqy.dao.JoinDao;
import com.dfqy.pojo.Join;
import com.dfqy.vo.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * Author : atyushu
 * Package : com.dfqy.service
 * ClassName : JoinService
 * Create : 2023/8/2 - 14:53
 * Version : v1.0
 * Description : The class of service for join.
 */
@Service
@Cacheable(keyGenerator = "keyg", cacheNames = "join")
@Transactional(rollbackFor = Exception.class, propagation = Propagation.SUPPORTS)
public class JoinService {

    @Autowired
    private JoinDao joinDao;

    @CacheEvict(allEntries = true, cacheNames = "join")
    public int insert(Join join) {
        return joinDao.insert(join);
    }

    @CacheEvict(allEntries = true, cacheNames = "join")
    public int delete(long... id) {
        return joinDao.delete(id);
    }

    @CacheEvict(allEntries = true, cacheNames = "join")
    public int update(Join join) {
        return joinDao.update(join);
    }

    public Join getById(long id) {
        return joinDao.getById(id);
    }

    public Page<Join> page(int page, int limit, Date jointimeStart, Date jointimeEnd, String phone, String uname, byte isattend, long eventid) {
        return new Page<>(joinDao.page(page, limit, jointimeStart, jointimeEnd, phone, uname, isattend, eventid), page, joinDao.countByLike(jointimeStart, jointimeEnd, phone, uname, isattend, eventid), limit);
    }

    @CacheEvict(allEntries = true, cacheNames = "join")
    public int absent(long id) {
        return joinDao.absent(id);
    }

    @CacheEvict(allEntries = true, cacheNames = "join")
    public int attend(long id) {
        return joinDao.attend(id);
    }

    public Page<Join> getByEventId(int page, int limit, long eventid) {
        return new Page<>(joinDao.getByEventId(page, limit, eventid), page, joinDao.countByEventId(eventid), limit);
    }
}
